<template>
  <div class="customer-service-container">
    <div class="customer-service-wrapper">
      <!-- 顶部标题栏 -->
      <div class="service-header">
        <router-link to="/">
          <div class="header-back" @click="goBack">
            <svg viewBox="0 0 24 24" width="24" height="24">
              <path
                fill="#333"
                d="M20 11H7.83l5.59-5.59L12 4l-8 8 8 8 1.41-1.41L7.83 13H20v-2z"
              />
            </svg>
          </div>
          <div class="header-title">宠百汇</div>
        </router-link>
      </div>

      <!-- 横向菜单区域 -->
      <div class="horizontal-menu">
        <div class="menu-item" @click="navigateTo('priceProtection')">
          <div class="menu-icon">
            <svg viewBox="0 0 24 24" width="24" height="24">
              <path
                fill="#ff6f00"
                d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 18c-4.41 0-8-3.59-8-8s3.59-8 8-8 8 3.59 8 8-3.59 8-8 8zm.31-8.86c-1.77-.45-2.34-.94-2.34-1.67 0-.84.79-1.43 2.1-1.43 1.38 0 1.9.66 1.94 1.64h1.71c-.05-1.34-.87-2.57-2.49-2.97V5H10.9v1.69c-1.51.32-2.72 1.3-2.72 2.81 0 1.79 1.49 2.69 3.66 3.21 1.95.46 2.34 1.15 2.34 1.87 0 .53-.39 1.39-2.1 1.39-1.6 0-2.23-.72-2.32-1.64H8.04c.1 1.7 1.36 2.66 2.86 2.97V19h2.34v-1.67c1.52-.29 2.72-1.16 2.73-2.77-.01-2.2-1.9-2.96-3.66-3.42z"
              />
            </svg>
          </div>
          <div class="menu-text">价保中心</div>
        </div>
        <div class="menu-item" @click="navigateTo('vipBenefits')">
          <div class="menu-icon">
            <svg viewBox="0 0 24 24" width="24" height="24">
              <path
                fill="#ff6f00"
                d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 18c-4.41 0-8-3.59-8-8s3.59-8 8-8 8 3.59 8 8-3.59 8-8 8zm-5.5-2.5l7.51-3.49L17.5 6.5 9.99 9.99 6.5 17.5zm5.5-6.6c.61 0 1.1.49 1.1 1.1s-.49 1.1-1.1 1.1-1.1-.49-1.1-1.1.49-1.1 1.1-1.1z"
              />
            </svg>
          </div>
          <div class="menu-text">VIP权益</div>
        </div>
        <div class="menu-item" @click="navigateTo('activityIssues')">
          <div class="menu-icon">
            <svg viewBox="0 0 24 24" width="24" height="24">
              <path
                fill="#ff6f00"
                d="M19 3h-4.18C14.4 1.84 13.3 1 12 1c-1.3 0-2.4.84-2.82 2H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm-7 0c.55 0 1 .45 1 1s-.45 1-1 1-1-.45-1-1 .45-1 1-1zm2 14H7v-2h7v2zm3-4H7v-2h10v2zm0-4H7V7h10v2z"
              />
            </svg>
          </div>
          <div class="menu-text">活动问题</div>
        </div>
        <div class="menu-item" @click="navigateTo('productReviews')">
          <div class="menu-icon">
            <svg viewBox="0 0 24 24" width="24" height="24">
              <path
                fill="#ff6f00"
                d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 18c-4.41 0-8-3.59-8-8s3.59-8 8-8 8 3.59 8 8-3.59 8-8 8zm-5.5-2.5l7.51-3.49L17.5 6.5 9.99 9.99 6.5 17.5zm5.5-6.6c.61 0 1.1.49 1.1 1.1s-.49 1.1-1.1 1.1-1.1-.49-1.1-1.1.49-1.1 1.1-1.1z"
              />
            </svg>
          </div>
          <div class="menu-text">商品评价</div>
        </div>
      </div>

      <!-- 对话框区域 -->
      <div class="dialog-container" ref="dialogContainer">
        <!-- 历史咨询记录 -->
        <div class="history-record" @click="viewHistory">
          <div class="record-item highlight">点击查看历史咨询记录</div>
        </div>

        <!-- 客服欢迎语 -->
        <div class="service-welcome">
          <div class="welcome-avatar">
            <img src="./客服头像.png" alt="小蜜头像" />
          </div>
          <div class="welcome-message">
            <div class="message-text">亲，我是小宠，很高兴为您服务！</div>
            <div class="message-text">亲，遇到什么问题可以和小宠说一下吗？</div>
          </div>
        </div>

        <!-- 用户消息 -->
        <div
          v-for="(message, index) in messages"
          :key="index"
          class="user-message"
        >
          <div class="message-content">{{ message.text }}</div>
          <div class="message-avatar">
            <img src="./touxiang.jpg" alt="用户头像" />
          </div>
        </div>
      </div>

      <!-- 底部输入框 -->
      <div class="service-footer">
        <div class="footer-input">
          <input
            type="text"
            placeholder="输入您的问题..."
            v-model="inputMessage"
            @keyup.enter="sendMessage"
          />
        </div>
        <div class="footer-actions">
          <div class="action-icon" @click="sendMessage">
            <svg viewBox="0 0 24 24" width="24" height="24">
              <path fill="#ff6f00" d="M2.01 21L23 12 2.01 3 2 10l15 2-15 2z" />
            </svg>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "CustomerService",
  data() {
    return {
      inputMessage: "",
      messages: [],
    };
  },
  methods: {
    sendMessage() {
      if (this.inputMessage.trim() === "") return;

      this.messages.push({
        text: this.inputMessage,
      });

      this.inputMessage = "";

      // 滚动到底部
      this.$nextTick(() => {
        const container = this.$refs.dialogContainer;
        container.scrollTop = container.scrollHeight;
      });
    },
    goBack() {
      // 返回上一页逻辑
      this.$router.go(-1);
    },
    showMore() {
      // 显示更多选项逻辑
      alert("显示更多选项");
    },
    viewHistory() {
      // 查看历史记录逻辑
      alert("查看历史咨询记录");
    },
    navigateTo(routeName) {
      // 根据不同的路由名称跳转到不同页面
      const routes = {
        priceProtection: "/price-protection",
        vipBenefits: "/vip-benefits",
        activityIssues: "/activity-issues",
        productReviews: "/product-reviews",
      };

      if (routes[routeName]) {
        this.$router.push(routes[routeName]);
      }
    },
  },
};
</script>

<style scoped>
.customer-service-container {
  display: flex;
  justify-content: center;
  margin: -5px;
  padding: 15px;
  align-items: center;
  background-color: #f8f8f8;
}

.customer-service-wrapper {
  width: 70%;
  height: 95vh;
  display: flex;
  flex-direction: column;
  background-color: #fff9e6;
  border-radius: 15px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  overflow: hidden;
}

/* 顶部标题栏样式 */
.service-header {
  height: 50px;
  background-color: #f4efd2;
  display: flex;
  align-items: center;
  padding: 0 20px;
  flex-shrink: 0;
}
.service-header a {
  display: flex;
  text-decoration: none;
}

.header-back {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.header-title {
  font-size: 18px;
  font-weight: 600;
  color: #333;
  cursor: pointer;
}

/* 横向菜单区域 */
.horizontal-menu {
  display: flex;
  justify-content: space-around;
  padding: 15px 0;
  background-color: #f7f3dd;
  border-bottom: 1px solid #f8f9af;
  flex-shrink: 0;
}

.menu-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 25%;
  cursor: pointer;
  transition: all 0.2s;
}

.menu-item:hover {
  transform: translateY(-3px);
}

.menu-icon {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 0px;
}

.menu-text {
  font-size: 14px;
  color: #333;
  text-align: center;
  margin-top: 5px;
}

/* 对话框区域 */
.dialog-container {
  flex: 1;
  overflow-y: auto;
  padding: 15px;
  background-image: url(https://gw.alicdn.com/imgextra/i2/O1CN01hDFYyl1Wgh5FnOlvc_!!6000000002818-55-tps-750-700.svg);
  background-size: cover;
}

/* 历史咨询记录 */
.history-record {
  margin-bottom: 15px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
}

.history-record:hover {
  opacity: 0.8;
}

.record-item {
  font-size: 15px;
}

/* 客服欢迎语 */
.service-welcome {
  display: flex;
  margin-bottom: 15px;
}

.welcome-avatar {
  width: 42px;
  height: 42px;
  margin-right: 12px;
  flex-shrink: 0;
}

.welcome-avatar img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  border: 2px solid #a2a2a2;
}

.welcome-message {
  background-color: #fff;
  border-radius: 12px;
  padding: 12px 16px;
  max-width: 70%;
  position: relative;
}

.welcome-message::before {
  content: "";
  position: absolute;
  left: -8px;
  top: 15px;
  width: 0;
  height: 0;
  border-top: 8px solid transparent;
  border-bottom: 8px solid transparent;
  border-right: 8px solid #fff;
}

.message-text {
  font-size: 14px;
  line-height: 1.5;
  color: #333;
}

/* 用户消息 */
.user-message {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 15px;
}

.message-content {
  background-color: #f4efd2;
  border-radius: 12px;
  padding: 12px 16px;
  max-width: 70%;
  margin-right: 12px;
  word-break: break-word;
}

.message-avatar {
  width: 42px;
  height: 42px;
  flex-shrink: 0;
}

.message-avatar img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
}

/* 底部输入框 */
.service-footer {
  background-color: #f4efd2;
  padding: 10px 15px;
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.footer-input {
  flex: 1;
  background-color: #fff;
  border-radius: 20px;
  padding: 8px 15px;
  margin-right: 10px;
  border: 1px solid #f8f9af;
}

.footer-input input {
  width: 100%;
  border: none;
  background: transparent;
  outline: none;
  font-size: 14px;
}

.footer-actions {
  display: flex;
}

.action-icon {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: #fff;
  border-radius: 50%;
  border: 1px solid #ffd600;
  cursor: pointer;
  transition: all 0.2s;
}

.action-icon:hover {
  background-color: #ffd600;
}

.highlight {
  color: #ff6f00;
  font-weight: 500;
}
</style>
